package leetcode.code784.LetterCasePermutation;

import java.util.ArrayList;
import java.util.List;

public class Solution78401 extends LetterCasePermutation {

	@Override
	public List<String> letterCasePermutation(String s) {
		return f(s, 0);
	}

	private List<String> f(String s, int i) {
		List<String> result = new ArrayList<>();
		if (i == s.length() - 1) {
			String s1 = ("" + s.charAt(i)).toLowerCase();
			String s2 = ("" + s.charAt(i)).toUpperCase();
			if (s1.equals(s2)) {
				result.add(s1);
			} else {
				result.add(s1);
				result.add(s2);
			}
		} else {
			List<String> rest = f(s, i + 1);
			String s1 = ("" + s.charAt(i)).toLowerCase();
			String s2 = ("" + s.charAt(i)).toUpperCase();
			for (String r : rest) {
				if (s1.equals(s2)) {
					result.add(s1 + r);
				} else {
					result.add(s1 + r);
					result.add(s2 + r);
				}
			}
		}
		return result;
	}

	public static void main(String[] args) {
		Solution78401 so = new Solution78401();
		so.debug1();
//		System.out.println("1".toUpperCase());
//		System.out.println("1".toLowerCase());
//		System.out.println("a".toUpperCase());
//		System.out.println("a".toLowerCase());
	}

}
